﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASTBuilder
{
    class CustomException : Exception
    {
        private CommandType typeOfCommand;
        private String errorMsg;

        public CustomException(String message)
            : base()
        {
            this.errorMsg = message;
        }
        public CustomException(CommandType someType) : base()
        {
            this.typeOfCommand = someType;
        }

        public override string ToString()
        {
            String result = "Exception: ";

            if (errorMsg != null)
            {
                return result + errorMsg;
            }
            else
            {
                switch (typeOfCommand)
                {
                    case CommandType.ERRORALREADYDECLARED:
                        result += "Variable is already declared";
                        break;
                    case CommandType.ERRORNOSUCHID:
                        result += "Unknown or undeclared variable";
                        break;
                    case CommandType.ERRORNULLARGUMENT:
                        result += "Argument is missing";
                        break;
                    case CommandType.ERRORUNCOMPATIBLETYPES:
                        result += "Operands are of incompatible types";
                        break;
                    case CommandType.ERRORUNDECLAREDID:
                        result += "Undeclared variable";
                        break;
                    default:
                        result += "some weird shit happened...";
                        break;
                }
                return result;
            }
        }
    }
}
